<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>家族资料库 - 家族树</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.8/dist/chart.umd.min.js"></script>
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#3B82F6',
                        secondary: '#10B981',
                        accent: '#8B5CF6',
                        dark: '#1E293B',
                        light: '#F8FAFC'
                    },
                    fontFamily: {
                        sans: ['Inter', 'system-ui', 'sans-serif'],
                    },
                }
            }
        }
    </script>
    <style type="text/tailwindcss">
        @layer utilities {
            .content-auto {
                content-visibility: auto;
            }
            .text-shadow {
                text-shadow: 0 2px 4px rgba(0,0,0,0.1);
            }
            .transition-custom {
                transition: all 0.3s ease;
            }
            .card-hover {
                @apply hover:shadow-lg hover:-translate-y-1 transition-all duration-300;
            }
            .nav-link {
                @apply relative px-3 py-2 text-gray-700 hover:text-primary transition-colors duration-200;
            }
            .nav-link::after {
                @apply content-[''] absolute bottom-0 left-0 w-0 h-0.5 bg-primary transition-all duration-200;
            }
            .nav-link:hover::after {
                @apply w-full;
            }
        }
    </style>
</head>
<body class="bg-gray-50 font-sans text-gray-800 min-h-screen flex flex-col">
    <!-- 顶部导航栏 -->
    <header class="sticky top-0 z-50 bg-white shadow-sm transition-all duration-300" id="navbar">
        <div class="container mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex justify-between items-center h-16">
                <div class="flex items-center">
                    <a href="index.html" class="flex items-center">
                        <i class="fa fa-sitemap text-primary text-2xl mr-2"></i>
                        <span class="font-bold text-xl text-dark">家族树</span>
                    </a>
                </div>
                
                <!-- 桌面导航 -->
                <nav class="hidden md:flex space-x-8">
                    <a href="index.html" class="nav-link">首页</a>
                    <a href="library.html" class="nav-link text-primary border-b-2 border-primary">家族资料库</a>
                    <a href="ai-access.html" class="nav-link">AI快速访问</a>
                    <a href="honors.html" class="nav-link">家族荣誉榜</a>
                    <a href="disgraces.html" class="nav-link">家族耻辱榜</a>
                </nav>
                
                <!-- 移动端菜单按钮 -->
                <div class="md:hidden">
                    <button id="menu-toggle" class="text-gray-700 hover:text-primary focus:outline-none">
                        <i class="fa fa-bars text-xl"></i>
                    </button>
                </div>
            </div>
        </div>
        
        <!-- 移动端导航菜单 -->
        <div id="mobile-menu" class="hidden md:hidden bg-white shadow-md absolute w-full">
            <div class="px-4 py-3 space-y-2">
                <a href="index.html" class="block px-3 py-2 text-gray-700 hover:bg-gray-100 rounded-md">首页</a>
                <a href="library.html" class="block px-3 py-2 text-primary bg-blue-50 rounded-md">家族资料库</a>
                <a href="ai-access.html" class="block px-3 py-2 text-gray-700 hover:bg-gray-100 rounded-md">AI快速访问</a>
                <a href="honors.html" class="block px-3 py-2 text-gray-700 hover:bg-gray-100 rounded-md">家族荣誉榜</a>
                <a href="disgraces.html" class="block px-3 py-2 text-gray-700 hover:bg-gray-100 rounded-md">家族耻辱榜</a>
            </div>
        </div>
    </header>

    <main class="flex-grow">
        <!-- 页面标题 -->
        <section class="bg-gradient-to-r from-primary to-accent text-white py-12">
            <div class="container mx-auto px-4 sm:px-6 lg:px-8">
                <h1 class="text-3xl sm:text-4xl font-bold text-center mb-2 text-shadow">家族资料库</h1>
                <p class="text-center opacity-90 max-w-2xl mx-auto">探索和管理家族的珍贵资料、照片、文档和历史记录，传承家族记忆。</p>
            </div>
        </section>

        <!-- 内容区域 -->
        <section class="py-12">
            <div class="container mx-auto px-4 sm:px-6 lg:px-8">
                <!-- 媒体类型筛选 -->
                <div class="mb-8">
                    <div class="flex flex-wrap gap-2 justify-center mb-6">
                        <button class="px-4 py-2 bg-primary text-white rounded-full text-sm font-medium">全部</button>
                        <button class="px-4 py-2 bg-gray-200 text-gray-700 rounded-full text-sm font-medium hover:bg-gray-300 transition-colors">照片</button>
                        <button class="px-4 py-2 bg-gray-200 text-gray-700 rounded-full text-sm font-medium hover:bg-gray-300 transition-colors">视频</button>
                        <button class="px-4 py-2 bg-gray-200 text-gray-700 rounded-full text-sm font-medium hover:bg-gray-300 transition-colors">文档</button>
                        <button class="px-4 py-2 bg-gray-200 text-gray-700 rounded-full text-sm font-medium hover:bg-gray-300 transition-colors">音频</button>
                    </div>

                    <!-- 搜索框 -->
                    <div class="max-w-2xl mx-auto mb-8">
                        <div class="relative">
                            <input type="text" placeholder="搜索资料库..." class="w-full px-4 py-3 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent pl-10">
                            <i class="fa fa-search absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400"></i>
                        </div>
                    </div>
                </div>

                <!-- 媒体内容容器 -->
                <div id="media-container" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
                    <!-- 加载状态 -->
                    <div class="col-span-full text-center py-12">
                        <div class="inline-block animate-spin rounded-full h-12 w-12 border-t-2 border-b-2 border-primary mb-4"></div>
                        <p class="text-gray-600">加载家族资料中...</p>
                    </div>
                </div>

                <!-- 上传按钮 -->
                <div class="mt-12 text-center">
                    <button id="upload-media" class="px-6 py-3 bg-secondary text-white rounded-lg font-medium hover:bg-secondary/90 transition-colors flex items-center mx-auto">
                        <i class="fa fa-upload mr-2"></i> 上传新资料
                    </button>
                </div>
            </div>
        </section>
    </main>

    <!-- 页脚 -->
    <footer class="bg-dark text-white py-12">
        <div class="container mx-auto px-4 sm:px-6 lg:px-8">
            <div class="grid grid-cols-1 md:grid-cols-4 gap-8">
                <div>
                    <h3 class="text-lg font-bold mb-4 flex items-center">
                        <i class="fa fa-sitemap text-primary mr-2"></i> 家族树
                    </h3>
                    <p class="text-gray-400 text-sm">连接过去，现在和未来，构建完整的家族历史图谱。</p>
                </div>
                <div>
                    <h4 class="font-bold mb-4">功能导航</h4>
                    <ul class="space-y-2 text-gray-400 text-sm">
                        <li><a href="index.html" class="hover:text-primary transition-colors">首页</a></li>
                        <li><a href="library.html" class="hover:text-primary transition-colors">家族资料库</a></li>
                        <li><a href="ai-access.html" class="hover:text-primary transition-colors">AI快速访问</a></li>
                        <li><a href="honors.html" class="hover:text-primary transition-colors">家族荣誉榜</a></li>
                        <li><a href="disgraces.html" class="hover:text-primary transition-colors">家族耻辱榜</a></li>
                    </ul>
                </div>
                <div>
                    <h4 class="font-bold mb-4">帮助中心</h4>
                    <ul class="space-y-2 text-gray-400 text-sm">
                        <li><a href="#" class="hover:text-primary transition-colors">使用指南</a></li>
                        <li><a href="#" class="hover:text-primary transition-colors">常见问题</a></li>
                        <li><a href="#" class="hover:text-primary transition-colors">联系支持</a></li>
                    </ul>
                </div>
                <div>
                    <h4 class="font-bold mb-4">联系我们</h4>
                    <ul class="space-y-2 text-gray-400 text-sm">
                        <li class="flex items-center"><i class="fa fa-envelope-o mr-2"></i> support@familytree.com</li>
                        <li class="flex items-center"><i class="fa fa-phone mr-2"></i> +86 123 4567 8910</li>
                    </ul>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-8 pt-8 text-center text-gray-500 text-sm">
                <p>&copy; 2023 家族树应用. 保留所有权利.</p>
            </div>
        </div>
    </footer>

    <!-- JavaScript -->
    <script>
        // 移动端菜单切换
        document.getElementById('menu-toggle').addEventListener('click', function() {
            const mobileMenu = document.getElementById('mobile-menu');
            mobileMenu.classList.toggle('hidden');
        });

        // 导航栏滚动效果
        window.addEventListener('scroll', function() {
            const navbar = document.getElementById('navbar');
            if (window.scrollY > 10) {
                navbar.classList.add('shadow-md');
                navbar.classList.remove('shadow-sm');
            } else {
                navbar.classList.remove('shadow-md');
                navbar.classList.add('shadow-sm');
            }
        });

        // 平滑滚动
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });

        // API交互功能
        async function fetchMediaData() {
            try {
                const response = await fetch('http://localhost:3000/api/media');
                const media = await response.json();
                console.log('媒体资料数据:', media);
                updateMediaUI(media);
            } catch (error) {
                console.error('获取媒体资料失败:', error);
                const mediaContainer = document.getElementById('media-container');
                mediaContainer.innerHTML = '<div class="col-span-full text-center py-12"><p class="text-red-500">加载失败，请稍后重试</p></div>';
            }
        }

        function updateMediaUI(media) {
            const mediaContainer = document.getElementById('media-container');
            if (media.length === 0) {
                mediaContainer.innerHTML = '<div class="col-span-full text-center py-12"><p class="text-gray-500">暂无媒体资料，请上传新资料</p></div>';
                return;
            }

            mediaContainer.innerHTML = '';
            media.forEach(item => {
                const mediaCard = document.createElement('div');
                mediaCard.className = 'bg-white rounded-lg shadow-md overflow-hidden card-hover';
                
                // 根据媒体类型选择图标
                let mediaIcon = 'fa-file-o';
                if (item.type.includes('图片') || item.type.includes('photo')) {
                    mediaIcon = 'fa-image';
                } else if (item.type.includes('视频') || item.type.includes('video')) {
                    mediaIcon = 'fa-video-camera';
                } else if (item.type.includes('文档') || item.type.includes('document')) {
                    mediaIcon = 'fa-file-text-o';
                } else if (item.type.includes('音频') || item.type.includes('audio')) {
                    mediaIcon = 'fa-music';
                }

                mediaCard.innerHTML = `
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-12 h-12 rounded-full bg-primary/10 flex items-center justify-center text-primary mr-4">
                                <i class="fa ${mediaIcon} text-xl"></i>
                            </div>
                            <div>
                                <h3 class="text-lg font-bold">${item.title}</h3>
                                <p class="text-gray-500 text-sm">类型: ${item.type}</p>
                            </div>
                        </div>
                        <div class="flex justify-between items-center mt-4">
                            <span class="text-gray-400 text-sm">关联成员: ${item.member_id ? 'ID: ' + item.member_id : '无'}</span>
                            <a href="${item.url}" class="text-primary hover:text-primary/80 transition-colors flex items-center" target="_blank">
                                <span>查看</span>
                                <i class="fa fa-external-link ml-1"></i>
                            </a>
                        </div>
                    </div>
                `;
                mediaContainer.appendChild(mediaCard);
            });
        }

        // 上传按钮点击事件
        document.getElementById('upload-media').addEventListener('click', function() {
            alert('媒体上传功能即将上线，敬请期待！');
        });

        // 页面加载完成后获取数据
        document.addEventListener('DOMContentLoaded', fetchMediaData);
    </script>
</body>
</html>